home *** CD-ROM | disk | FTP | other *** search
/ Oxygen Multimedia Graphics 22 / Oxygen Multimedia Graphics 22.iso / pc / System / OX22 / Internal_53_Draggable.ls < prev    next >
Encoding:
Text File  |  2008-03-12  |  2.4 KB  |  84 lines

  1. property pSprite, pLocOffset, pActive, pConstrained
  2.  
  3. on getBehaviorDescription me
  4.   return "DRAGGABLE" & RETURN & RETURN & "Makes sprite respond to clicking and dragging the mouse button, similar to setting the draggable property of the sprite. " & "Sprite movement may constrained to the stage area." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Graphic members" & RETURN & RETURN & "If using with digital video or other sprites in which Direct to Stage is an option, disable Direct to Stage for best results." & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Constrain to stage?"
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Makes a sprite draggable. " & "The sprite will move along with the cursor while the mouse button is held down."
  9. end
  10.  
  11. on beginSprite me
  12.   pSprite = sprite(me.spriteNum)
  13.   vMember = pSprite.member
  14.   case vMember.type of
  15.     #animGif, #flash, #quickTimeMedia, #digitalVideo, #vectorShape:
  16.       if vMember.directToStage then
  17.         alert("Sprite" && pSprite.spriteNum & ": Direct To Stage media may cause" && "playback problems with the 'Moveable Sprite' behavior.")
  18.       end if
  19.   end case
  20.   pActive = 0
  21. end
  22.  
  23. on mouseUp me
  24.   mDrag(0)
  25. end
  26.  
  27. on mouseDown me
  28.   mDrag(1)
  29. end
  30.  
  31. on prepareFrame me
  32.   if the mouseUp then
  33.     mDrag(0)
  34.   end if
  35.   if pActive then
  36.     mDragSprite(me)
  37.   end if
  38. end
  39.  
  40. on mDrag vActive
  41.   pActive = vActive
  42.   pLocOffset = pSprite.loc - the mouseLoc
  43.   sendAllSprites(#Active_Sprite, the currentSpriteNum * pActive)
  44. end
  45.  
  46. on mDragSprite
  47.   pSprite.loc = the mouseLoc + pLocOffset
  48.   if pConstrained then
  49.     vLeftDiff = pSprite.rect.left
  50.     if vLeftDiff < 0 then
  51.       pSprite.locH = pSprite.locH - vLeftDiff
  52.     end if
  53.     vRightDiff = pSprite.rect.right - (the stage).sourceRect.width
  54.     if vRightDiff > 0 then
  55.       pSprite.locH = pSprite.locH - vRightDiff
  56.     end if
  57.     vTopDiff = pSprite.rect.top
  58.     if vTopDiff < 0 then
  59.       pSprite.locV = pSprite.locV - vTopDiff
  60.     end if
  61.     vBottomDiff = pSprite.rect.bottom - (the stage).sourceRect.height
  62.     if vBottomDiff > 0 then
  63.       pSprite.locV = pSprite.locV - vBottomDiff
  64.     end if
  65.   end if
  66. end
  67.  
  68. on Forwarded_mouseDown me
  69.   if not pActive then
  70.     mDrag(1)
  71.   end if
  72.   return the currentSpriteNum
  73. end
  74.  
  75. on isOKToAttach me, aSpriteType, aSpriteNum
  76.   return aSpriteType = #graphic
  77. end
  78.  
  79. on getPropertyDescriptionList
  80.   vPDList = [:]
  81.   setaProp(vPDList, #pConstrained, [#comment: "Constrain to stage", #format: #boolean, #default: 1])
  82.   return vPDList
  83. end
  84.